package com.albon.main;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.albon.baseball.BaseballLeague;
import com.albon.soccer.SoccerLeague;
import com.albon.sportsalarm.R;

public class MenuFragment extends Fragment implements OnClickListener {
	
	private LinearLayout soccer_group;
	private LinearLayout baseball_group;
	private LinearLayout basketball_group;
	private ImageView soccer_item;
	private ImageView baseball_item;
	private ImageView basketball_item;
	
	
	private ScrollView soccer_list;
	private ScrollView baseball_list;
	private ScrollView basketball_list;
	
	private LinearLayout epl_group; //EPL
	private LinearLayout lfp_group; //프리메가리가
	private LinearLayout lnp_group; //세리에A
	private LinearLayout dfl_group; //분데스리가
	private LinearLayout ligue1_group; //리그1
	private LinearLayout spl_group;  //SPL
	private LinearLayout uefacl_group; //챔피언스리그
	private LinearLayout uefacup_group; //유로파
	private LinearLayout k_league_group; //k리그
	
	private LinearLayout mlb_group; //MLB
	private LinearLayout kbo_group; //KBO
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		//View v = inflater.inflate(R.layout.frame_menu, null);
		
		//v.findViewById(R.id.menu1).setOnClickListener(this);
		//v.findViewById(R.id.menu2).setOnClickListener(this);
		/*View v = inflater.inflate(R.layout.soccer_main, null);
		v.findViewById(R.id.soccer_item).setOnClickListener(this);
		v.findViewById(R.id.baseball_item).setOnClickListener(this);
		v.findViewById(R.id.soccer_list);
		v.findViewById(R.id.baseball_list);*/
		return inflater.inflate(R.layout.sports_main, container ,false);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		
	}

	private void switchFragment(Fragment fragment) {
		if (getActivity() == null)
			return;
		
		if (getActivity() instanceof AlbonMain) {
			AlbonMain fca = (AlbonMain) getActivity();
			fca.switchContent(fragment);
		}
	}
	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	
		init();	
		
	}
	
	private void init() {
		// TODO Auto-generated method stub
		
		baseball_group = (LinearLayout)getView().findViewById(R.id.baseball_group);
		baseball_group.setOnClickListener(this);
		soccer_group = (LinearLayout)getView().findViewById(R.id.soccer_group);
		soccer_group.setOnClickListener(this);
		basketball_group = (LinearLayout)getView().findViewById(R.id.basketball_group);
		basketball_group.setOnClickListener(this);
		
		baseball_item = (ImageView)getView().findViewById(R.id.baseball_item);
		baseball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_baseball_on));
		soccer_item = (ImageView)getView().findViewById(R.id.soccer_item);		
		soccer_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_soccer_off));
		basketball_item = (ImageView)getView().findViewById(R.id.basketball_item);
		basketball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_basketball_off));
		
		soccer_list = (ScrollView)getView().findViewById(R.id.soccer_list);
		baseball_list = (ScrollView)getView().findViewById(R.id.baseball_list);
		basketball_list = (ScrollView)getView().findViewById(R.id.basketball_list);
		
		epl_group = (LinearLayout)getView().findViewById(R.id.epl_group);
		lfp_group = (LinearLayout)getView().findViewById(R.id.lfp_group);
		lnp_group = (LinearLayout)getView().findViewById(R.id.lnp_group);
		dfl_group = (LinearLayout)getView().findViewById(R.id.dfl_group);
		ligue1_group = (LinearLayout)getView().findViewById(R.id.ligue1_group);
		spl_group = (LinearLayout)getView().findViewById(R.id.spl_group);
		uefacl_group = (LinearLayout)getView().findViewById(R.id.uefacl_group);
		uefacup_group = (LinearLayout)getView().findViewById(R.id.uefacup_group);
		k_league_group = (LinearLayout)getView().findViewById(R.id.k_league_group);
		epl_group.setOnClickListener(this);
		lfp_group.setOnClickListener(this);
		lnp_group.setOnClickListener(this);
		dfl_group.setOnClickListener(this);
		ligue1_group.setOnClickListener(this);
		spl_group.setOnClickListener(this);
		uefacl_group.setOnClickListener(this);
		uefacup_group.setOnClickListener(this);
		k_league_group.setOnClickListener(this);
		
		mlb_group = (LinearLayout)getView().findViewById(R.id.mlb_group);
		kbo_group = (LinearLayout)getView().findViewById(R.id.kbo_group);
		mlb_group.setOnClickListener(this);
		kbo_group.setOnClickListener(this);
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		Fragment newContent = null;
		
		
		switch (v.getId()) {
		case R.id.soccer_group:
			
			soccer_list.setVisibility(View.VISIBLE);
			baseball_list.setVisibility(View.GONE);
			basketball_list.setVisibility(View.GONE);
			
			soccer_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_soccer_on));			
			baseball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_baseball_off));			
			basketball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_basketball_off));
			//newContent = new MainFragment1();
			break;
		case R.id.baseball_group:
			soccer_list.setVisibility(View.GONE);
			baseball_list.setVisibility(View.VISIBLE);
			basketball_list.setVisibility(View.GONE);
			
			soccer_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_soccer_off));			
			baseball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_baseball_on));			
			basketball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_basketball_off));
			//newContent = new MainFragment2();
			break;
		case R.id.basketball_group:
			soccer_list.setVisibility(View.GONE);
			baseball_list.setVisibility(View.GONE);
			basketball_list.setVisibility(View.VISIBLE);
			soccer_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_soccer_off));			
			baseball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_baseball_off));			
			basketball_item.setImageDrawable(getResources().getDrawable(R.drawable.ic_main_menu_basketball_on));
			//newContent = new MainFragment2();
			break;

		case R.id.epl_group:
			  /*Intent epl_group_intent = new Intent(getActivity(), SoccerLeague.class);
			  epl_group_intent.putExtra("league_name", "epl");
			  epl_group_intent.putExtra("league_title",  getText(R.string.epl).toString());
			  epl_group_intent.putExtra("world",  0);
			  startActivity(epl_group_intent);*/
			  newContent = new SoccerFragment(getText(R.string.epl).toString(), "epl", 0);
			  
			break;
	
		case R.id.lfp_group:
			/*Intent lfp_group_intent = new Intent(getActivity(), SoccerLeague.class);
			lfp_group_intent.putExtra("league_name", "lfp");
			lfp_group_intent.putExtra("league_title", getText(R.string.lfp).toString());
			lfp_group_intent.putExtra("world",  0);
			startActivity(lfp_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.lfp).toString(), "lfp", 0);
			break;
			
		case R.id.lnp_group:
			/*Intent lnp_group_intent = new Intent(getActivity(), SoccerLeague.class);
			lnp_group_intent.putExtra("league_name", "lnp");
			lnp_group_intent.putExtra("league_title", getText(R.string.lnp).toString());
			lnp_group_intent.putExtra("world",  0);
			startActivity(lnp_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.lnp).toString(), "lnp", 0);
			break;
		case R.id.dfl_group:
			/*Intent dfl_group_intent = new Intent(getActivity(), SoccerLeague.class);
			dfl_group_intent.putExtra("league_name", "dfl");
			dfl_group_intent.putExtra("league_title", getText(R.string.dfl).toString());
			dfl_group_intent.putExtra("world",  0);
			startActivity(dfl_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.dfl).toString(), "dfl", 0);
			break;
			
		case R.id.ligue1_group:
			/*Intent ligue1_group_intent = new Intent(getActivity(), SoccerLeague.class);
			ligue1_group_intent.putExtra("league_name", "ligue1");
			ligue1_group_intent.putExtra("league_title", getText(R.string.ligue1).toString());
			ligue1_group_intent.putExtra("world",  0);
			startActivity(ligue1_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.ligue1).toString(), "ligue1", 0);
			break;
			
		case R.id.spl_group:
			/*Intent spl_group_intent = new Intent(getActivity(), SoccerLeague.class);
			spl_group_intent.putExtra("league_name", "spl");
			spl_group_intent.putExtra("league_title", getText(R.string.spl).toString());
			spl_group_intent.putExtra("world",  0);
			startActivity(spl_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.spl).toString(), "spl", 0);
			break;
			
		case R.id.uefacl_group:
			/*Intent uefacl_group_intent = new Intent(getActivity(), SoccerLeague.class);
			uefacl_group_intent.putExtra("league_name", "uefacl");
			uefacl_group_intent.putExtra("league_title", getText(R.string.uefacl).toString());
			uefacl_group_intent.putExtra("world",  0);
			startActivity(uefacl_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.uefacl).toString(), "uefacl", 0);
			break;
			
		case R.id.uefacup_group:
			/*Intent uefacup_group_intent = new Intent(getActivity(), SoccerLeague.class);
			uefacup_group_intent.putExtra("league_name", "uefacup");
			uefacup_group_intent.putExtra("league_title", getText(R.string.uefacup).toString());
			uefacup_group_intent.putExtra("world",  0);
			startActivity(uefacup_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.uefacup).toString(), "uefacup", 0);
			break;
			
		case R.id.k_league_group:
			/*Intent k_league_group_intent = new Intent(getActivity(), SoccerLeague.class);
			k_league_group_intent.putExtra("league_name", "k_league");
			k_league_group_intent.putExtra("league_title", getText(R.string.k_league).toString());
			k_league_group_intent.putExtra("world",  1);
			startActivity(k_league_group_intent);*/
			newContent = new SoccerFragment(getText(R.string.k_league).toString(), "k_league", 1);
			break;
			
		case R.id.mlb_group:
			 /*Intent mlb_group_intent = new Intent(getActivity(), BaseballLeague.class);
			 	mlb_group_intent.putExtra("league_name", "mlb");
			 	mlb_group_intent.putExtra("league_title",  getText(R.string.mlb).toString());
			 	mlb_group_intent.putExtra("world",  0);
			  startActivity(mlb_group_intent);*/
			newContent = new BaseballFragment(getText(R.string.mlb).toString(), "mlb", 0);
			break;
			
		case R.id.kbo_group:
			/*Intent kbo_group_intent = new Intent(getActivity(), BaseballLeague.class);
			kbo_group_intent.putExtra("league_name", "kbo");
			kbo_group_intent.putExtra("league_title",  getText(R.string.kbo).toString());
			kbo_group_intent.putExtra("world",  1);
			startActivity(kbo_group_intent);*/
			newContent = new BaseballFragment(getText(R.string.kbo).toString(), "kbo", 1);
			break;	
		}
		
		if (newContent != null)
			switchFragment(newContent);
	}
}
